<template>
    <bi-form ref="form">
        <bi-form-item label="模型名称">
            <bi-input name="title" v-model="fromData.title" placeholder="请输入模型名称" required />
        </bi-form-item>
        <bi-form-item label="模型类型">
            <bi-select v-model="fromData.type"  placeholder="请选择类型" required >
                <bi-select-option v-for="title,key in modelType" :key="key"  :value="key" :label="title"></bi-select-option>
            </bi-select>
        </bi-form-item>
    </bi-form>
</template>

<script>
export default{
    dialog:{
        title:'编辑模型',
    },
    data(){

        let fromData =  {
            model_id:'',
            type:'',
            title:''
        }

        this.$assign(fromData,this.item);

        return {
            fromData,
            modelType:this.$pageData.modelType,
        }
    },
    props:{
        item:{
            type:Object,
        }
    },
    methods:{
        dialogOk(){
            
            if (this.$refs.form.check()){
                this.$ajax({
                    url:this.$url({app:'web','controller':'admin.model',action:'edit'}),
                    data:{
                        ...this.fromData
                    },
                    success:(data)=>{
                        if (this.fromData.model_id=='') {
                            this.$toast('添加成功');
                        }else{
                            this.$toast('修改成功');
                        }
                        this.dialog.callback(this.fromData);
                        this.dialog.close();
                    }
                })
            }

            return false;

        }
    }
}
</script>